﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QDT.Common;

namespace QDT.Core.Projects
{
    public class ProjectException:Exception
    {
        public ProjectException():base()
        {
            StatusCode = ProjectException.Unknow;
        }

        public ProjectException(string message):base(message)
        {
            StatusCode = ProjectException.Unknow;
        }

        public ProjectException(string message, Exception inner):base(message,inner)
        {
            StatusCode = ProjectException.Unknow;
        }

        public ProjectException(int statusCode,Project project)
        {
            StatusCode = statusCode;
            Project = project;
        }

        public ProjectException(int statusCode)
            : this(statusCode, null)
        {
            
        }

        public int StatusCode { get; set; }

        public Project Project { get; set; }

        /// <summary>
        /// 未知的异常
        /// </summary>
        public const int Unknow = 0;

        /// <summary>
        /// 项目当前状态不允许删除
        /// </summary>
        public const int NotDeleteStatus = 1;

        public override string Message
        {
            get
            {
                switch(StatusCode) {
                    case NotDeleteStatus:
                        return "{0}状态不允许删除.".FormatWith(Project == null ? "" : Project.Status.ToLocalizable());
                    default:
                        return base.Message;
                }
            }
        }
    }
}
